package com.pactera.madp.cp.controller.sidebar.employee;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.pactera.madp.common.core.util.R;
import com.pactera.madp.common.security.annotation.Inner;
import com.pactera.madp.cp.api.entity.CorpEntity;
import com.pactera.madp.cp.api.vo.*;
import com.pactera.madp.cp.api.vo.contactloss.SidebarNoCommunicationVO;
import com.pactera.madp.cp.service.EmployeeMarketingEventRemindService;
import com.pactera.madp.cp.service.ICorpService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 经理视图-营销事件提醒控制层
 *
 * @author zkd
 * @date 2022/5/5 17:20
 */
@Slf4j
@RestController
@RequestMapping("/employee-marketing-event-remind")
@Api(value = "employee-marketing-event-remind", tags = "经理视图-营销事件提醒")
public class EmployeeMarketingEventRemindController {

    @Autowired
    private EmployeeMarketingEventRemindService employeeMarketingEventRemindService;
    @Autowired
    private ICorpService corpService;

    @GetMapping("/overview")
    @ApiOperation(value = "概览")
    public R<MarketingEventRemindOverviewVO> contactData(@RequestParam(required = true) String wxUserId) {
        return R.ok(employeeMarketingEventRemindService.getOverViewData(wxUserId));
    }

    @GetMapping("/no-communication-page")
    @ApiOperation(value = "获取未交流客户列表")
    public R<IPage<SidebarNoCommunicationVO>> getNoCommunicationContactPage(Page page, @RequestParam(required = true) String wxUserId) {
        return R.ok(employeeMarketingEventRemindService.getNoCommunicationPage(page,wxUserId));
    }

    @GetMapping("/product-expire-page")
    @ApiOperation(value = "获取产品到期列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name="wxUserId",value="微信成员id",dataType ="String"),
            @ApiImplicitParam(name="queryParam",value="查询参数(客户名称/客户号/手机号)",dataType ="String")
    })
    public R<IPage<SidebarProductExpireVO>> getProductExpirePage(Page page,
                                                                 @RequestParam(name = "wxUserId",required = true) String wxUserId,
                                                                 @RequestParam(name = "queryParam",required = false) String queryParam) {
        return R.ok(employeeMarketingEventRemindService.getProductExpirePage(page,wxUserId,queryParam));
    }

    @GetMapping("/birthday-remind-page")
    @ApiOperation(value = "获取生日提醒列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name="wxUserId",value="微信成员id",dataType ="String"),
            @ApiImplicitParam(name="queryParam",value="查询参数(客户名称/客户号/手机号)",dataType ="String")
    })
    public R<IPage<SidebarBirthdayRemindVO>> getBirthdayRemindPage(Page page,
                                                                   @RequestParam(name = "wxUserId",required = true) String wxUserId,
                                                                   @RequestParam(name = "queryParam",required = false) String queryParam) {
        return R.ok(employeeMarketingEventRemindService.getBirthdayRemindPage(page,wxUserId,queryParam));
    }

    @GetMapping("/current-balance-page")
    @ApiOperation(value = "获取活期余额列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name="custName",value="客户名",dataType ="String"),
            @ApiImplicitParam(name="custAum",value="客户aum,1-5万以下,2-5万-10万,3-10万-20万,4-20万以上",dataType ="String")
    })
    public R<IPage<SidebarCurrentBalanceVO>> getCurrentBalancePage(Page page,
                                                                   @RequestParam(name = "wxUserId",required = true) String wxUserId,
                                                                   @RequestParam(name = "custName",required = false) String custName,
                                                                   @RequestParam(name = "custAum",required = false) String custAum) {
        return R.ok(employeeMarketingEventRemindService.getCurrentBalancePage(page,wxUserId,custName,custAum));
    }

    @GetMapping("/marketing-clue-page")
    @ApiOperation(value = "获取营销线索列表")
    public R<IPage<SidebarMarketingClueVO>> getMarketingCluePage(Page page, @RequestParam(required = true) String wxUserId) {
        return R.ok(employeeMarketingEventRemindService.getMarketingCluePage(page,wxUserId));
    }

    @GetMapping("/marketing-clue-details-page")
    @ApiOperation(value = "获取营销线索详情列表")
    public R<IPage<SidebarMarketingClueDetailsVO>> getMarketingClueDetailsPage(Page page,@RequestParam(required = true) String distinctId) {
        return R.ok(employeeMarketingEventRemindService.getMarketingClueDetailsPage(page,distinctId));
    }

    @PostMapping("/send-msg")
    @ApiOperation(value = "远程调用-营销事件提醒消息发送")
    @Inner
    public void sendMarketingEventRemindMsg(HttpServletResponse response) {
        List<CorpEntity> list = corpService.list();
        list.forEach(l -> {
            employeeMarketingEventRemindService.sendMarketingEventRemindMsg(l.getCorpId(),response);
        });
    }

}
